package com.tianqi.ui.dao;



import com.tianqi.ui.bean.Data;
import com.tianqi.ui.bean.WeatherInfo;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class DataDAO extends BaseDAO {
    private Connection con = null;
    private Statement st = null;
    private ResultSet rs = null;

    public Data getCity(String city){
        Data data = null;
        String sql = "select * from w_city where `city`= '"+city+"'";
        try{
            // 调用父类的方法获取链接
            con = getCon();
            st = con.createStatement();
            rs = st.executeQuery(sql);
            if(rs.next()){
                data = new Data();
                data.setCity(rs.getString("city"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll(rs,st,con);
        }
        return data;
    }

//    保存天气信息
    public int save(Data data){
        // 拼接sql
        String sql = "insert into w_city values('"+data.getCity()+"')";
        try{
            con = getCon();
            st = con.createStatement();
            return st.executeUpdate(sql);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll(rs,st,con);
        }
        return 0;
    }
}
